package com.fmbah.ohiojx;

import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @author fb
 * @description Application
 * @date 2019年10月14日
 */
@Slf4j
@SpringBootApplication
@RestController
public class ManageWebApplication extends SpringBootServletInitializer {

    @RequestMapping("/")
    public Object index() {
        return "欢迎.....";
    }

    @RequestMapping("/login")
    public Object login() {
        Subject currentUser = SecurityUtils.getSubject();
        UsernamePasswordToken token = new UsernamePasswordToken("username", "password");
        currentUser.login(token);
        return "登入.....";
    }

    @RequestMapping("/logout")
    public Object logout() {
        try {
            Subject currentUser = SecurityUtils.getSubject();
            currentUser.logout();
        } catch (Exception e) {
        }
        return "登出.....";
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        log.info("----ManageWebApplication 启动----");
        return application.sources(ManageWebApplication.class);
    }

    public static void main(String[] args) {
        SpringApplication.run(ManageWebApplication.class, args);
        log.info("----ManageWebApplication 启动----");
    }

}
